package logic

import (
	"context"
	"errors"
	"four/sss/weeekrpc/internal/models"
	"four/sss/weeekrpc/internal/svc"
	"four/sss/weeekrpc/pb/weeekrpc"
	"gorm.io/gorm"

	"github.com/zeromicro/go-zero/core/logx"
)

type CapacityLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCapacityLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CapacityLogic {
	return &CapacityLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// Capacity todo: 查询容量
func (l *CapacityLogic) Capacity(in *weeekrpc.CapacityRequest) (*weeekrpc.CapacityResponse, error) {
	// todo: add your logic here and delete this line
	userid := in.Userid
	user, _ := models.GetUserInfo(models.Users{
		Model: gorm.Model{ID: uint(userid)},
	})
	var r weeekrpc.CapacityResponse
	r.VipLv = 0
	r.Capacity = 0
	if user.ID == 0 {
		return &r, errors.New("用户不存在")
	}
	r.VipLv = int64(user.Vip)
	r.Capacity = int64(user.Capacity)
	return &r, nil
}
